import { ref, computed, watch } from "vue";
export const CodeTable = (collectionType, filters = "", isReverse = false) => {
  let selectedValue = ref("");

  const options = ref([
    { label: "码表选项1", value: "1" },
    { label: "码表选项2", value: "2" },
    { label: "码表选项3", value: "3" },
    { label: "码表选项4", value: "4" },
  ]);

  //选项过滤
  const filteredOptions = computed(() => {
    const filter = filters ? filters.split(",") : [];
    if (filter.length === 0 || isReverse) {
      return options.value;
    }
    if (isReverse) {
      return options.value.filter((option) => !filter.includes(option.value));
    } else {
      return options.value.filter((option) => filter.includes(option.value));
    }
  });

  watch(selectedValue, (newValue) => {
    emit("update:modelValue", newValue);
  });

  return () => {
    return (
      <el-select
          v-model={selectedValue}
          style={{width: "100%"}}
          clearable
          placeholder="请选择"
        >
          {filteredOptions.value.map((item, index) => {
            return (
              <el-option
                key={index}
                label={item.label}
                value={item.value}
              ></el-option>
            );
          })}
        </el-select>
    );
  };
};
